package com.fit.WatchShop.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.WatchShop.interfaces.User;
import com.fit.WatchShop.interfaces.Watch;
import com.fit.WatchShop.service.Watches;


public class ViewWatch {
	
	@Inject
	@Property
	private Watches watches;
	
	@Property
	private Watch currentWatch;
	
	@InjectPage
	private WatchDetails watchDetailsPage;
	
	@InjectPage
	private EntryBuy entryBuy;
	
	@OnEvent(component = "watchDetailsLink")
	Object onShowDetails(String type) {
		Watch chosenWatch = watches.retrieveSingleWatch(type);
		watchDetailsPage.setChosenWatch(chosenWatch);
		return watchDetailsPage;
	}
	
	@OnEvent(component = "entryWatchLink")
	Object onWatchLink(String type) {
		entryBuy.setBuyWatch(type);
		return entryBuy;
	}
	
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
	
//	@Persist
//	private Watch singleWatch;
//
//	public Watch getSingleWatch() {
//		return singleWatch;
//	}
//
//	public void setSingleWatch(Watch singleWatch) {
//		this.singleWatch = singleWatch;
//	}
}
